package cn.ronghuanet;

import cn.ronghuanet.auth.interceptor.AuthInterceptor;
import cn.ronghuanet.auth.interceptor.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@MapperScan("cn.ronghuanet.*.mapper")
@SpringBootApplication
@ServletComponentScan("cn.ronghuanet.auth.listener") // 扫描监听器
@EnableCaching  // 开启对于springCache的使用
public class CarAppStart implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(CarAppStart.class,args);
    }

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")     // 要拦截所有的请求
                .excludePathPatterns("/login/**","/logout","/user/phone/register",
                        "/shop/settlement","/fastDfs/**","/verifyCode/**",
                        "/user/bind/**");
    }

    //    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(authInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns("/login","/loginout");
//    }
}
